package servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class HiServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //给servletContext属性添加属性
//        ServletContext servletContext = super.getServletConfig().getServletContext();
        ServletContext servletContext = req.getServletContext();
        servletContext.setAttribute("name", "lmy");
        servletContext.setAttribute("name", "lmy~");
        servletContext.removeAttribute("name");

        //获取session对象
        HttpSession session = req.getSession();
        //添加attribute
        session.setAttribute("age", 100);
        session.setAttribute("age", 400);
        session.removeAttribute("age");


        System.out.println("HiServlet 处理完毕...");
    }
}
